﻿@{
    ViewBag.Title = "ShoppingCar";
    Layout = "~/Views/Shared/_LayoutPageAll.cshtml";
}
<script src="~/js/jquery-1.8.2.js"></script>
<script>

    ///分页显示
    $(document).ready(function () {
        CheAll();
        var id = @Session["UserID"];
        $.ajax({
            type: "get",
            url: "http://localhost:19451/api/Car/GetSelCar",
            data: {UserID:id},
            success: function (res) {
                var price = 0;
                
                $(res).each(function (i, item) {
                    var table = "";
                    table += "   <tr class=\"odd\">";
                    table += "   <td> <input  id='CheOne' type='checkbox'  name='CheOne'  value='" + item.CarId + "' /></td>";
                    table += "   <td class=\"image\"><a href=\"/product/convallis-sit-amet-tellus\"><img  typeof=\"foaf:Image\" src='" + item.CarPhoto + "' width=\"50\" height=\"31\" alt=\"\" /></a></td>";
                    table += "   <td class=\"desc\"><a href=\"/product/convallis-sit-amet-tellus\">" + item.CarName + "</a></td>";
                    table += "   <td class=\"qty\">";
                    table += "   <div class=\"form-item form-type-uc-quantity form-item-items-0-qty\">";
                    table += "   <div class=\"gw_num\"><input type=\"button\" value=\" - \" style=\"background-color:white\" id=\"Jian" + item.CarId + "\"onclick = \"Jian(" + item.CarId + ")\" /><input type=\"text\" value=\"" + item.CarNum + "\" readonly style=\"width:40px; text-align:center\" id=\"text" + item.CarId + "\" /><input type=\"button\" value=\"+\" style=\"background-color:white\"  id=\"Add" + item.CarId + "\" onclick = \"Add(" + item.CarId + ")\" />";
                    table += "   </div>";
                    table += "   </td>";
                    table += "   <td class=\"price\"><span class=\"uc-price\">" + item.CarPrice + "</span></td>";
                    table += "   <td class=\"remove\" ><input  type=\"button\" id=\"edit-items-0-remove\" name=\"remove-0\" value=\"Remove\" class=\"form-submit\"  onclick = \"Del(" + item.CarId + ")\"/></td>";
                    table += "   </tr>";
                    $('#tablebody').append(table);
                    price += item.CarPrice * item.CarNum;
                })
                
                var a = "<hr ></hr><span id=\"subtotal-title\">总计：</span> <span class=\"uc-price\">$" + price + "</span>";
                $('#sum').html(a);
            }
        })
    })
  
        function CheAll()
        {
            $("#CheAll").click(function () {

                var isChecked = $(this).prop("checked");

                $("input[name='CheOne']").prop("checked", isChecked);

            });
        }
           
          



    function Del(CarId) {
        if (confirm("是否删除？")) {
            $.ajax({
                type: "get",
                url: "http://localhost:19451/api/Car/GetDelCar",
                data: { CarId: CarId },
                success: function (res) {
                    history.go(-1);
                }
            })
        }
    }
    function Add(CarId) {


        var num = parseInt($("#text" + CarId + "").val());

        $("#text" + CarId).val(num + 1)
        $.ajax({
            type: "get",
            url: "http://localhost:19451/api/Car/GetAddUpdate",
            data: { CarId: CarId },
            success: function (res) {
                location.href = "/Home/ShoppingCar";
            }
        })
    }
    function Jian(CarId) {
        var num = parseInt($("#text" + CarId + "").val());
        if (num > 1) {
            $("#text" + CarId).val(num - 1)
            $.ajax({
                type: "get",
                url: "http://localhost:19451/api/Car/GetJianUpdate",
                data: { CarId: CarId },
                success: function (res) {
                    location.href = "/Home/ShoppingCar";
                   
                }
            })
        }
        else {
            $("#text" + CarId).val(num)
        }

    }
    function Buy() {
        var id = @Session["UserID"];
        if (confirm("是否结账？")) {
            var ids="";
            for(var i=0;i<$("input[name='CheOne']").length;i++)
            {
                
                if($("input[name='CheOne']").eq(i).attr("checked")=="checked")
                {
                    var n=$("input[name='CheOne']").eq(i).val();
                    //ids+=n+',';
                    
                }
                $.ajax({
                    type: "get",
                    url: "http://localhost:19451/api/Order/GetAddOrders",
                    data: {carid:n,UserId:id},
                    success: function (res) {
                        
                    }
                });                                                          
            }
            alert("成功加入订单");
            location.href = "/Home/ShoppingCar";   
          
        }
    }
</script>
@*页面中心内容*@
<div class="content clearfix" >
    <div class="breadcrumbs">
        <h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="/">返回首页</a> » Shopping cart</div>
    </div>
    <div class="messages status">
        <strong>你选好的商品</strong>添加到 <a href="http://localhost:29242/Home/ShoppingCar">您的购物车</a>.
    </div>
    @*购物车块*@
    <div id="content" class="column left-content"  >
        <div class="section">
            <h1 class="title" id="page-title">购物车</h1>
            <div class="region region-content">
                <div id="block-system-main" class="block block-system">
                    <div class="content">
                        <div id="cart-form-pane">
                            <form action="/cart" method="post" id="uc-cart-view-form" accept-charset="UTF-8">
                                <div>
                                    <div class="uc-default-submit"><input type="submit" id="edit-update" name="update-cart" value="修改" class="form-submit" /></div>
                                    <div>
                                        <table class="sticky-enabled">
                                        <thead style="padding-left:10px"><tr><th><input id="CheAll" type="checkbox" />全选</th><th>商品图</th><th>商品名</th><th><abbr title="Quantity">数量</abbr></th><th>单价</th><th>删除</th> </tr></thead>
                                            <tbody id="tablebody"></tbody>

                                        </table>
                                        <div id="Febye">

                                        </div>
                                        <div id="sum">
                                                        
                                        </div>
                                                    </div>
                                    <div class="form-actions form-wrapper" id="edit-actions"><a href="http://localhost:29242/Home/ChinaMenu?idd=1">继续购买</a><input type="button" id="edit-checkout--2" name="op" value="结算" class="form-submit" onclick="Buy()" /></div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @*右边模块*@
    <div id="sidebar-second" class="column sidebar right-content">
        <div class="section">
            <div class="region region-sidebar-second">
                @*电话热线*@
                <div id="block-block-3" class="block block-block">
                    <div class="content">
                        <div class="call-us">
                            <span class="label">请拨打！！！</span><span class="pop phone">0800/ 567 345</span><span class="label">工作时间：</span><span class="pop">0-24h</span>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div> 
</div>

